<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AdaPaySdk;

class AdaPayCommon extends \AdaPay\AdaPay
{
    public function packageRequestUrl($requestParams = [])
    {
        $adapayFuncCode = $requestParams["adapay_func_code"];
        if(empty($adapayFuncCode)) {
            try {
                throw new \Exception("adapay_func_code不能为空");
            } catch (\Exception $e) {
                echo $e->getMessage();
            }
        }
        $adapayApiVersion = isset($requestParams["adapay_api_version"]) ? $requestParams["adapay_api_version"] : "v1";
        $this->getGateWayUrl($this->gateWayType);
        return $this->gateWayUrl . "/" . $adapayApiVersion . "/" . str_replace(".", "/", $adapayFuncCode);
    }
    public function requestAdapay($params = [], $merchantKey = "")
    {
        if(!empty($merchantKey)) {
            self::$rsaPrivateKey = $merchantKey;
            $this->ada_tools->rsaPrivateKey = $merchantKey;
        }
        $request_params = $params;
        $req_url = $this->packageRequestUrl($request_params);
        $request_params = $this->format_request_params($request_params);
        $header = $this->get_request_header($req_url, $request_params, self::$header);
        $this->result = $this->ada_request->curl_request($req_url, $request_params, $header, $is_json = true);
    }
    public function requestAdapayUits($params = [], $merchantKey = "")
    {
        $this->gateWayType = "page";
        if(!empty($merchantKey)) {
            self::$rsaPrivateKey = $merchantKey;
            $this->ada_tools->rsaPrivateKey = $merchantKey;
        }
        $request_params = $params;
        $req_url = $this->packageRequestUrl($request_params);
        $request_params = $this->format_request_params($request_params);
        echo $req_url;
        $header = $this->get_request_header($req_url, $request_params, self::$header);
        $this->result = $this->ada_request->curl_request($req_url, $request_params, $header, $is_json = true);
    }
    public function queryAdapay($params = [], $merchantKey = "")
    {
        if(!empty($merchantKey)) {
            self::$rsaPrivateKey = $merchantKey;
            $this->ada_tools->rsaPrivateKey = $merchantKey;
        }
        ksort($params);
        $request_params = $params;
        $req_url = $this->packageRequestUrl($request_params);
        $request_params = $this->format_request_params($request_params);
        $header = $this->get_request_header($req_url, http_build_query($request_params), self::$headerText);
        $this->result = $this->ada_request->curl_request($req_url . "?" . http_build_query($request_params), "", $header, false);
    }
    public function queryAdapayUits($params = [], $merchantKey = "")
    {
        $this->gateWayType = "page";
        if(!empty($merchantKey)) {
            self::$rsaPrivateKey = $merchantKey;
            $this->ada_tools->rsaPrivateKey = $merchantKey;
        }
        ksort($params);
        $request_params = $params;
        $req_url = $this->packageRequestUrl($request_params);
        $request_params = $this->format_request_params($request_params);
        $header = $this->get_request_header($req_url, http_build_query($request_params), self::$headerText);
        $this->result = $this->ada_request->curl_request($req_url . "?" . http_build_query($request_params), "", $header, false);
    }
    public function array_remove($arr, $key)
    {
        if(!array_key_exists($key, $arr)) {
            return $arr;
        }
        $keys = array_keys($arr);
        $index = array_search($key, $keys);
        if($index !== false) {
            array_splice($arr, $index, 1);
        }
        return $arr;
    }
    public function format_request_params($request_params)
    {
        $request_params = $this->array_remove($request_params, "adapay_func_code");
        $request_params = $this->array_remove($request_params, "adapay_api_version");
        $request_params = $this->do_empty_data($request_params);
        return $request_params;
    }
}

?>